package com.fan.analysis.module.show.service.impl;


import com.fan.analysis.common.domain.ResponseDTO;
import com.fan.analysis.module.analysis.group.domain.entity.UserInfoEntity;
import com.fan.analysis.module.analysis.group.domain.entity.UserRelationEntity;
import com.fan.analysis.module.show.dao.ShowDao;
import com.fan.analysis.module.show.domain.dto.CallRecordDto;
import com.fan.analysis.module.show.domain.dto.MessageRecordDto;
import com.fan.analysis.module.show.domain.vo.CallRecordVo;
import com.fan.analysis.module.show.domain.vo.MessageVo;
import com.fan.analysis.module.show.service.ShowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fan
 * @date 2021/10/08 16:44
 **/
@Service
public class ShowServiceImpl implements ShowService {


    private final ShowDao showDao;

    @Autowired
    public ShowServiceImpl(ShowDao showDao) {
        this.showDao = showDao;
    }

    /**
     * 通话电话获取其通话记录
     *
     * @param callRecordDto 参数
     * @return 通话记录
     */
    @Override
    public ResponseDTO<List<CallRecordVo>> getCallRecordComplete(CallRecordDto callRecordDto) {

        // 查找记录
        List<CallRecordVo> callRecordVos = showDao.listCallRecordInfos(callRecordDto.getPhoneNum(), callRecordDto.getStartTime(), callRecordDto.getEndTime());

        // 查找电话号码所处城市
        String city = showDao.getCityByPhoneNum(callRecordDto.getPhoneNum());
        if (city != null) {
            for (CallRecordVo callRecordVo : callRecordVos) {
                callRecordVo.setCity(city);
            }
        }

        return ResponseDTO.succData(callRecordVos);
    }

    /**
     * 通话手机号获取其短信记录
     *
     * @param messageRecordDto 参数
     * @return 短信记录
     */
    @Override
    public ResponseDTO<List<MessageVo>> getMessageRecordComplete(MessageRecordDto messageRecordDto) {


        List<MessageVo> messageVos = showDao.listMessageRecordInfos(messageRecordDto.getPhoneNum(), messageRecordDto.getStartTime(), messageRecordDto.getEndTime());
        // 查找电话号码所处城市
        String city = showDao.getCityByPhoneNum(messageRecordDto.getPhoneNum());
        if (city != null) {
            for (MessageVo messageVo : messageVos) {
                messageVo.setCity(city);
            }
        }
        return ResponseDTO.succData(messageVos);
    }

    /**
     * 获取所有用户关系
     *
     * @return 用户关系
     */
    @Override
    public ResponseDTO<List<UserRelationEntity>> getAllUserRelationInfo() {

        List<UserRelationEntity> relationEntities = showDao.listUserRelationInfos();

        return ResponseDTO.succData(relationEntities);
    }

    /**
     * 获取所有用户信息
     *
     * @return 所有用户信息
     */
    @Override
    public ResponseDTO<List<UserInfoEntity>> getAllUserInfo() {

        List<UserInfoEntity> userInfoEntities = showDao.listUserInfos();

        return ResponseDTO.succData(userInfoEntities);
    }
}
